﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using InSafetyAirServer.Database;


namespace InSafetyAirServer.Controller
{
    class AccountCtr
    {        
        public static Account createAccount(Person person, string username,string password, string email,byte access)
        {
            SQLDatabaseDataContext _db = new SQLDatabaseDataContext();
            Account account = new Account();
            account.Person = person;
            account.username = username;
            account.email = email;
            account.access = access;
            string salt = Functions.getInstance().generateSalt();
            account.salt = salt;
            account.password = Functions.getInstance().CalculateMD5Hash(password + salt);
            _db.Accounts.InsertOnSubmit(account);
            _db.SubmitChanges();
            return account;
        }

        public static Account checkLogin(string username,string password)
        {
            return Functions.getInstance().checkLogin(username, password);
        }


    }
}
